import { createRouter, createWebHistory } from 'vue-router'
import Index from '../components/Index.vue'
import Course from '../components/Course.vue'
import ali from '../components/ali.vue'
import Setting from '../components/Setting.vue'
import Upload from "../components/Upload.vue"
import WxLoginCallback from "../components/WxLoginCallback.vue"

const videoDetail = () => import('../components/videoDetail.vue');

const routes = [
  // {
  //   path: '/',
  //   name: 'Upload',
  //   component: Upload,
  //   meta: {
  //     title: '首页'
  //   }
  // },
  {
    path: '/',
    name: 'Index',
    component: Index,
    meta: {
      title: '首页'
    }
  },
  {
    path: '/course',
    name: 'Course',
    component: Course,
    props: true,
    meta: {
      title: '课程简介页'
    }
  },
  {
    path: '/video/:id',
    name: 'videoDetail',
    component: videoDetail,
    props: true,
    meta: {
      title: '视频播放页'
    }
  },
  {
    path: '/ali',
    name: 'ali',
    component: ali,
    meta: {
      title: '播放器'
    }
  },
  {
    path: '/setting',
    name: 'Setting',
    component: Setting,
    meta: {
      title: '个人设置'
    }
  },
  {
    path: '/wx/callback',
    name: 'callback',
    component: WxLoginCallback,
    props: true
  }
]

const router = createRouter({
  history: createWebHistory(),
  routes
})

// 全局导航守卫
router.beforeEach((to, from, next) => {
  // 设置页面标题
  if (to.meta.title) {
    document.title = to.meta.title;
  }
  next();
})

export default router

